//子进程向父进程发送信息
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <pthread.h>
#include <stdio.h>
#include <sys/wait.h>

int main(int argc,char*argv[])
{
    int arrfd[2] = {-1,-1};
    pid_t cpid;
    pipe(arrfd);
    cpid = fork();
    if(cpid < 0)
    {
        printf("error");
        close(arrfd[0]);
        close(arrfd[1]);
        return 1;
    }
    if(cpid > 0)
    {
        write(arrfd[1],"Hello",6);
        wait(NULL);//善后
    }
    else
    {//child
        char buf[8]="";
        read(arrfd[0],buf,6);
        printf("In child process,buf = %s\n",buf);
    }
    
    return 0;
}